// hyb_yl/krecovery/pages/after_operation/after_operation.js
var app = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    agreement_state:false,
    checked:false
  },
  choose_agreement:function(e){
    console.log(e)
    this.setData({
      agreement_state:true,
      checked:!this.data.checked
    })
  },
  closezhe:function(){
    this.setData({
      agreement_state:false
    })
  },
  buy_btn:function(e){
    var that = this;
    var checked=this.data.checked;
    var openid = wx.getStorageSync('openid')
    if(openid == '')
    {
      wx.showModal({
        cancelColor: '提示',
        content:'请先登录',
        success:function(con)
        {
          if(con.confirm)
          {
            wx.navigateTo({
              url: '/hyb_yl/sgin/sgin',
            })
          }else{
            wx.switchTab({
              url: '/hyb_yl/tabBar/index/index',
            })
          }
        }
      })
    }else if(!checked){
      wx.showToast({
        title: '请阅读并同意术后服务协议',
        icon:'none'
      })
    }else{

      app.util.request({
        'url':"entry/wxapp/green.getqylistser",
        data:{
          openid:wx.getStorageSync('openid')
        },
        success:function(res){
          var list = res.data.list;
          var j_id = res.data.j_id;
          if(j_id == false || j_id == 'false')
          {
            wx.showModal({
              title:"提示",
              showCancel:false,
              content: '请先添加患者信息',
              success:function(con)
              {
                if(con.confirm)
                {
                  wx.navigateTo({
                    url: '/hyb_yl/zhuanjiasubpages/pages/huanzhexinxi/huanzhexinxi?type=1&gren=1',
                  })
                }
              }
            })
          }else if(list.length == 0)
          {
            wx.showModal({
              title: '提示',
              content:"您暂无签约医生，请扫码签约",
              showCancel:false,
              success:function(con)
              {
                if(con.confirm)
                {
                  wx.scanCode({
                    success:function(re){
                      var data = re.path;
                      
                      var res = data.split("=")
                      
                      if(res.length > 2)
                      {
                        var zids = res[2].split("&");
                        var zid = zids[0]
                      }else if(res.length == 2)
                      {
                        var zid = res[1].split("%3D");
                        if(zid[1].indexOf("%26") >= 0)
                        {
                          zid = zid[1].split("%26");
                          zid = zid[0];
                        }else{
                          var zid = zid[1]
                        }
                        
                      }else{
                        var zids = res[1].split("%26")
                        var zidss = zids[0].split("%3D");
                        var zid = zidss[1]
                        var zid = res[1];
                        zid = zid.substr(6)
                      }
                      app.util.request({
                        'url': 'entry/wxapp/zhuanjia.checkcollect',
                        data: {
                          openid: wx.getStorageSync('openid'),
                          zid: zid,
                          cerated_type: 7, //签约专家
                        },
                        success: function (res) {
                          
                          if(res.data.ifqianyue == 1)
                          {
                            wx.showToast({
                              title: '签约中，请等待审核',
                            })
                          }else if(res.data.ifqianyue == 2)
                          {
                            // wx.navigateTo({
                            //   url: '/hyb_yl/krecovery/pages/choose_operation/choose_operation?id='+that.data.id+'&title='+that.data.title+'&keyword='+that.data.keyword+'&zid='+zid,
                            // })
                            wx.navigateTo({
                              url: '/hyb_yl/huanzhe/pages/private_services/private_services?zid='+zid+'&id='+that.data.id+'&title='+that.data.title+'&keyword='+that.data.keyword,
                            })
                          }else if(res.data.ifqianyue == 3 || res.data.ifqianyue == 4 || res.data.ifqianyue == 5 || res.data.ifqianyue == 0)
                          {
                            wx.navigateTo({
                              url: '/hyb_yl/huanzhe/pages/patient_report/patient_report?zid='+zid,
                            })
                          }else{
                            wx.navigateTo({
                              url: '/hyb_yl/huanzhe/pages/patient_report/patient_report?zid='+zid,
                            })
                            // wx.navigateTo({
                            //   url: '/hyb_yl/czhuanjiasubpages/pages/zhuanjiazhuye/zhuanjiazhuye?zid='+zid,
                            // })
                          }
                          
                        },
                      })
                    }
                  })
                  // wx.scanCode({
                  //   success:function(re){
                  //     var data = re.path;
                  //     console.log(data);
                  //     var res = data.split("=")
                  //     var zids = res[2].split("&");
                  //     var zid = zids[0]
                  //     // var zids = res[1].split("%26")
                  //     // var zidss = zids[0].split("%3D");
                  //     // var zid = zidss[1]
                      
                  //     app.util.request({
                  //       'url': 'entry/wxapp/zhuanjia.checkcollect',
                  //       data: {
                  //         openid: wx.getStorageSync('openid'),
                  //         zid: zid,
                  //         cerated_type: 7, //签约专家
                  //       },
                  //       success: function (res) {
                  //         console.log(res)
                  //         app.util.request({
                  //           'url': 'entry/wxapp/zhuanjia.savecollectup',
                  //           data: {
                  //             openid: wx.getStorageSync('openid'),
                  //             goods_id: zid,
                  //             cerated_type: 7,
                  //             ifqianyue: 1,
                  //             change: 1,
                  //           },
                  //           success: function (res) {
                  //             console.log(res);
                  //             wx.showToast({
                  //               title: '操作成功，请等待审核',
                  //               icon: 'none',
                  //               duration: 1500,
                  //               success: function () {
                  //                 //签约提醒
                  //                 app.util.request({
                  //                   'url': 'entry/wxapp/zhuanjia.remind',
                  //                   data: {
                  //                     openid: wx.getStorageSync('openid'),
                  //                     zid: zid,
                  //                     j_id: j_id
                  //                   },
                  //                   success: function (res) {
                  //                     that.setData({
                  //                       list: [],
                  //                       page: 0
                  //                     })
                  //                   }
                  //                 })
                  //               }
                  //             })
                  //           },
          
                  //         })
                  //       },
                  //     })
                  //   }
                  // })
                }
              }
            })
          }else{
            wx.showModal({
              title:"提示",
              content: '是否选择面签医生会诊',
              success:function(con)
              {
                if(con.confirm)
                {
                  wx.scanCode({
                    success:function(re){
                      var data = re.path;
                      
                      var res = data.split("=")
                      if(res.length > 2)
                      {
                        var zids = res[2].split("&");
                        var zid = zids[0]
                      }else if(res.length == 2)
                      {
                        var zid = res[1].split("%3D");
                        if(zid[1].indexOf("%26") >= 0)
                        {
                          zid = zid[1].split("%26");
                          zid = zid[0];
                        }else{
                          var zid = zid[1]
                        }
                      }else{
                        var zids = res[1].split("%26")
                        var zidss = zids[0].split("%3D");
                        var zid = zidss[1]
                        var zid = res[1];
                        zid = zid.substr(6)
                      }
                      app.util.request({
                        'url': 'entry/wxapp/zhuanjia.checkcollect',
                        data: {
                          openid: wx.getStorageSync('openid'),
                          zid: zid,
                          cerated_type: 7, //签约专家
                        },
                        success: function (res) {
                          
                          if(res.data.ifqianyue == 1)
                          {
                            wx.showToast({
                              title: '签约中，请等待审核',
                            })
                          }else if(res.data.ifqianyue == 2)
                          {
                            // wx.navigateTo({
                            //   url: '/hyb_yl/krecovery/pages/choose_operation/choose_operation?id='+that.data.id+'&title='+that.data.title+'&keyword='+that.data.keyword+'&zid='+zid,
                            // })
                            wx.navigateTo({
                              url: '/hyb_yl/huanzhe/pages/private_services/private_services?zid='+zid+'&id='+that.data.id+'&title='+that.data.title+'&keyword='+that.data.keyword,
                            })
                          }else if(res.data.ifqianyue == 3 || res.data.ifqianyue == 4 || res.data.ifqianyue == 5 || res.data.ifqianyue == 0)
                          {
                            wx.navigateTo({
                              url: '/hyb_yl/huanzhe/pages/patient_report/patient_report?zid='+zid,
                            })
                            // app.util.request({
                            //   'url': 'entry/wxapp/zhuanjia.savecollectup',
                            //   data: {
                            //     openid: wx.getStorageSync('openid'),
                            //     goods_id: zid,
                            //     cerated_type: 7,
                            //     ifqianyue: 1,
                            //     change: 1,
                            //   },
                            //   success: function (res) {
                            //     console.log(res);
                            //     wx.showToast({
                            //       title: '操作成功，请等待审核',
                            //       icon: 'none',
                            //       duration: 1500,
                            //       success: function () {
                            //         //签约提醒
                            //         app.util.request({
                            //           'url': 'entry/wxapp/zhuanjia.remind',
                            //           data: {
                            //             openid: wx.getStorageSync('openid'),
                            //             zid: zid,
                            //             j_id: j_id
                            //           },
                            //           success: function (res) {
                            //             that.setData({
                            //               list: [],
                            //               page: 0
                            //             })
                            //           }
                            //         })
                            //       }
                            //     })
                            //   },
            
                            // })
                          }else{
                            // wx.navigateTo({
                            //   url: '/hyb_yl/czhuanjiasubpages/pages/zhuanjiazhuye/zhuanjiazhuye?zid='+zid,
                            // })
                            wx.navigateTo({
                              url: '/hyb_yl/huanzhe/pages/patient_report/patient_report?zid='+zid,
                            })
                          }
                          
                        },
                      })
                    }
                  })
                }else{
                  wx.navigateTo({
                    url: '/hyb_yl/mycenter/pages/followDoc/followDoc?typs=siren_doc',
                  })
                }
              }
            })
          }
        }
      })
      
    }
    
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var that = this
    var bgc = wx.getStorageSync('color')
    var pinyin = options.ser_key
    var typs = options.typs;
    if (typs == 'query' && typs != undefined) {
      that.setData({
        typs: typs
      })
    }
    app.util.request({
      'url': 'entry/wxapp/index.neworder',
      data:{
        type:pinyin
      },
      success: function (res) {
        that.setData({
          neworder: res.data
        })
      },
      fail: function (err) {
        console.log(err)
      },
    })
    that.setData({
      pinyin: pinyin,
      bgc:bgc
    })
    wx.setNavigationBarColor({
      frontColor: "#ffffff",
      backgroundColor: bgc,
    })
    var id = options.id;
    var title = options.title;
    var keyword = options.keyword;
    that.setData({
      id:id,
      title:title,
      keyword:keyword
    })
    if(keyword == 'shuhoukangfu')
    {
      app.util.request({
        'url':"entry/wxapp/green.shuhoukangfu_count",
        success:function(res){
          that.setData({
            info:res.data
          })
        }
      })
    }
    
    app.util.request({
      'url': 'entry/wxapp/index.detailserones',
      data: {
        ser_key: pinyin
      },
      success: function (res) {
        console.log(res)
        that.setData({
          detail: res.data
        })
      },
      fail: function (err) {
        console.log(err)
      },
    })

  },
  tosee:function(){
    var that = this;
    wx.navigateTo({
      url: '/hyb_yl/czhuanjiasubpages/pages/estimate/estimate?key='+that.data.keyword,
    })
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})